<?php

namespace Home\Model;

use Think\Model;
use Home\Util\Tools;

/**
 * 支持模型
 */
class TestModel extends Model {

    /**
     * 发布用户的数据
     * 
     * @var array
     */
    public $user = array();

    /**
     * 梦想数据
     * 
     * @var array
     */
    public $dream = array();
    
    /**
     * @todo 测试获取token的方法
     * @author ghw
     */
    public function getToken($code){
    	/* import('@.Util.Tools');
    	//取access_token
    	$data = array(
    			'grant_type' => 'client_credential',
    			'appid' => C('APP_ID'),
    			'secret' => C('APP_SECRET'),
    	);
    	$return = json_decode(Tools::get('https://api.weixin.qq.com/cgi-bin/token', $data), true);
    	return $return; */
    	import('@.Util.Tools');
    	//取access_token
    	$data = array(
    			'appid' => C('APP_ID'),
    			'secret' => C('APP_SECRET'),
    			'code' => $code,
    			'grant_type' => 'authorization_code',
    	);
    	$return = json_decode(Tools::get('https://api.weixin.qq.com/sns/oauth2/access_token', $data), true);
    	session('weixin_openid', $return['openid']);
    	return $return['openid'];
    }

}
